<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<title>Test end values with fill modes after animation is removed</title>
<style type="text/css" media="screen">
  .box {
    position: relative;
    left: 100px;
    top: 10px;
    height: 100px;
    width: 100px;
    animation-delay: 0.1s;
    animation-duration: 0.1s;
    animation-timing-function: linear;
    animation-name: anim;
  }
  @keyframes anim {
    from { left: 200px; }
    to   { left: 300px; }
  }
  #a {
    background-color: blue;
    animation-fill-mode: none;
  }
  #b {
    background-color: red;
    animation-fill-mode: backwards;
  }
  #c {
    background-color: green;
    animation-fill-mode: forwards;
  }
  #d {
    background-color: yellow;
    animation-fill-mode: both;
  }
</style>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script type="text/javascript" charset="utf-8">
const numAnims = 4;
var animsFinished = 0;
const expectedEndValues = [
  {id: "a", value: 100},
  {id: "b", value: 100},
  {id: "c", value: 100},
  {id: "d", value: 100}
];

async_test(t => {
  function endTest() {
    for (var i=0; i < expectedEndValues.length; i++) {
      var el = document.getElementById(expectedEndValues[i].id);
      var expectedValue = expectedEndValues[i].value;
      var realValue = parseFloat(window.getComputedStyle(el).left);
      var diff = Math.abs(expectedValue - realValue);
      assert_less_than(diff, 5, "id: " + expectedEndValues[i].id + " expected: " + expectedValue + " actual: " + realValue);
    }
    t.done();
  }

  window.addEventListener("load", t.step_func(() => {
    document.addEventListener("animationend", t.step_func((event) => {
      event.target.style.animationName = "none";
      if (++animsFinished == numAnims) {
        t.step_timeout(endTest, 0); // this set timeout should be ok in the test environment
                                    // since we're just giving style a chance to resolve
      }
    }));
  }));
}, 'This test performs an animation of the left property with four different fill modes. It animates over 0.1 second with a 0.1 second delay. At the end of the animations, we remove the animation name which should cause the value to jump back to the unanimated style');
</script>
<div id="a" class="box">
  None
</div>
<div id="b" class="box">
  Backwards
</div>
<div id="c" class="box">
  Forwards
</div>
<div id="d" class="box">
  Both
</div>
